package com.situ.ymall.admin.mapper;

import java.util.List;

import com.situ.ymall.admin.entity.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface GoodsMapper {
    @Delete({
        "delete from goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into goods (id, goods_sort_id, ",
        "name, dscp, price, ",
        "version, color, ",
        "suit, count, status)",
        "values (#{id,jdbcType=INTEGER}, #{goodsSortId,jdbcType=INTEGER}, ",
        "#{name,jdbcType=VARCHAR}, #{dscp,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, ",
        "#{version,jdbcType=VARCHAR}, #{color,jdbcType=VARCHAR}, ",
        "#{suit,jdbcType=VARCHAR}, #{count,jdbcType=INTEGER}, #{status,jdbcType=INTEGER})"
    })
    int insert(Goods record);

    @Select({
        "select",
        "id, goods_sort_id, name, dscp, price, version, color, suit, count, status",
        "from goods",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="goods_sort_id", property="goodsSortId", jdbcType=JdbcType.INTEGER),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="dscp", property="dscp", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL),
        @Result(column="version", property="version", jdbcType=JdbcType.VARCHAR),
        @Result(column="color", property="color", jdbcType=JdbcType.VARCHAR),
        @Result(column="suit", property="suit", jdbcType=JdbcType.VARCHAR),
        @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER)
    })
    Goods selectByPrimaryKey(Integer id);

    @Select({
        "select",
        "id, goods_sort_id, name, dscp, price, version, color, suit, count, status",
        "from goods"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="goods_sort_id", property="goodsSortId", jdbcType=JdbcType.INTEGER),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="dscp", property="dscp", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL),
        @Result(column="version", property="version", jdbcType=JdbcType.VARCHAR),
        @Result(column="color", property="color", jdbcType=JdbcType.VARCHAR),
        @Result(column="suit", property="suit", jdbcType=JdbcType.VARCHAR),
        @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER)
    })
    List<Goods> selectAll();

    @Update({
        "update goods",
        "set goods_sort_id = #{goodsSortId,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "dscp = #{dscp,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=DECIMAL},",
          "version = #{version,jdbcType=VARCHAR},",
          "color = #{color,jdbcType=VARCHAR},",
          "suit = #{suit,jdbcType=VARCHAR},",
          "count = #{count,jdbcType=INTEGER},",
          "status = #{status,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Goods record);
}